<template>
  <div>
    <input type="text"
           placeholder="请输入要搜索的关键字"
           v-if="isShow"
           ref="input" />
    <button @click="focusInput"
            v-else>点击搜索</button>
  </div>
</template>

<script>
// dom.focus() 获取焦点
export default {
  data () {
    return {
      isShow: false
    }
  },
  methods: {
    focusInput(){
      this.isShow=!this.isShow

      this.$nextTick(()=>{
        this.$refs.input.focus()})
    }
  }
}
</script>

<style>
</style>